package Main;

import Tools.Generator;
import org.junit.Test;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

/**
 * @author 23083
 */
@SuppressWarnings("AlibabaMethodTooLong")
public class Main {
    private static int rough;
    private static int type;
    private static int num;
    private static Generator generator = new Generator();
    private static Random random = new Random();
    private static String s="";
    public static void main(String[] args) {
        init();
        produce(rough,type,num);
        System.out.println(s);
        write();
    }
    public static void write(){
        File file = new File("D://test.txt" );
        if (!file.exists()) {
            System.out.println("不存在");
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                FileReader fr = new FileReader("D://test.txt");
                FileWriter fw = new FileWriter(file);
                fw.write(s);
                fr.close();                         //关闭流
                fw.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else {
            System.out.println("存在");
            try {
                FileReader fr = new FileReader("D://test.txt");
                FileWriter fw = new FileWriter(file);               
                fw.write(s);
                fr.close();
                fw.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }
    }
    public static void init(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择运算数范围0~");
        rough = scanner.nextInt();
        System.out.println("请选择运算符类型");
        System.out.println("    1.全加运算     ");
        System.out.println("    2.全减运算     ");
        System.out.println("    3.全乘运算     ");
        System.out.println("    4.全除运算     ");
        System.out.println("    5.加减运算     ");
        System.out.println("    6.加乘运算     ");
        System.out.println("    7.加除运算     ");
        System.out.println("    8.减乘运算     ");
        System.out.println("    9.减除运算     ");
        System.out.println("    10.乘除运算     ");
        System.out.println("    0.综合运算     ");
        type = scanner.nextInt()%11;
        System.out.println("请选择出题数量: ");
        num = scanner.nextInt();
    }
    public static void produce(int rough,int type,int num){
        switch (type){
            case 1:
                for (int i = 0; i <num; i++) {
                    s=s+generator.generateAdd(rough)+"     ";
                };break;
            case 2:
                for (int i = 0; i <num; i++) {
                    s=s+generator.generateSubtract(rough)+"     ";
                };break;
            case 3:
                for (int i = 0; i <num; i++) {
                    s=s+generator.generateMultiply(rough)+"     ";
                };break;
            case 4:
                for (int i = 0; i <num; i++) {
                    s=s+generator.generateDivide(rough)+"     ";
                };break;
            case 5:
                for (int i = 0; i <num; i++) {
                    if (random.nextBoolean()){
                        s=s+generator.generateAdd(rough)+"     ";
                    }else {
                        s=s+generator.generateSubtract(rough)+"     ";
                    }
                };break;
            case 6:
                for (int i = 0; i <num; i++) {
                    if (random.nextBoolean()){
                        s=s+generator.generateAdd(rough)+"     ";
                    }else {
                        s=s+generator.generateMultiply(rough)+"     ";
                    }
                };break;
            case 7:
                for (int i = 0; i <num; i++) {
                    if (random.nextBoolean()){
                        s=s+generator.generateAdd(rough)+"     ";
                    }else {
                        s=s+generator.generateDivide(rough)+"     ";
                    }
                };break;
            case 8:
                for (int i = 0; i <num; i++) {
                    if (random.nextBoolean()){
                        s=s+generator.generateSubtract(rough)+"     ";
                    }else {
                        s=s+generator.generateMultiply(rough)+"     ";
                    }
                };break;
            case 9:
                for (int i = 0; i <num; i++) {
                    if (random.nextBoolean()){
                        s=s+generator.generateSubtract(rough)+"     ";
                    }else {
                        s=s+generator.generateDivide(rough)+"     ";
                    }
                };break;
            case 10:
                for (int i = 0; i <num; i++) {
                    if (random.nextBoolean()){
                        s=s+generator.generateMultiply(rough)+"     ";
                    }else {
                        s=s+generator.generateDivide(rough)+"     ";
                    }
                };break;
            case 0:
                for (int i = 0; i <num; i++) {
                    switch (random.nextInt(4)+1){
                        case 1:
                            s=s+generator.generateAdd(rough)+"     ";break;
                        case 2:
                            s=s+generator.generateSubtract(rough)+"     ";break;
                        case 3:
                            s=s+generator.generateMultiply(rough)+"     ";break;
                        case 4:
                            s=s+generator.generateDivide(rough)+"     ";break;
                        default:
                            throw new IllegalStateException("Unexpected value: " + random.nextInt(4) + 1);
                    }
                };break;
            default:
                throw new IllegalStateException("Unexpected value: " + type);
        }
    }
    @Test
    public void test(){
        produce(50,0,50);
        System.out.println(s);
    }
}
//12